package Thread;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class ThreadDemo17 {
    public static void main(String[] args) {
        BlockingDeque<Integer> deque = new LinkedBlockingDeque<>();
        //消费者
        Thread t1 = new Thread(()->{
            while (true){
                try {
                    System.out.println("消费者元素: "+deque.take());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        //生产者
        Thread t2 = new Thread(()->{  int value = 0;
            while (true){
                try {
                    System.out.println("生产元素: "+value);
                    deque.put(value++);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();
    }
}
